package zh.demo.datasource;

/**
 * Created by zhangheng on 2017/10/30.
 */
public final class DynamicDataSourceHolder {

    private static final ThreadLocal<String> local = new ThreadLocal<String>();

    public static ThreadLocal<String> getLocal() {
        return local;
    }

    /**
     * 读可能是多个库
     */
    public static void read() {

        local.set(DynamicDataSourceGlobal.read.getType());
    }

    /**
     * 写只有一个库
     */
    public static void write() {
        //log.debug("writewritewrite");
        local.set(DynamicDataSourceGlobal.write.getType());
    }

    public static String getJdbcType() {
        return local.get();
    }
    /*private static final ThreadLocal<DynamicDataSourceGlobal> holder = new ThreadLocal<>();

    private DynamicDataSourceHolder(){
        //
    }

    public static void putDataSource(DynamicDataSourceGlobal dataSource){
        holder.set(dataSource);
    }

    public static DynamicDataSourceGlobal getDataSource(){
        return holder.get();
    }

    public static void clearDataSource() {
        holder.remove();
    }*/

}
